package com.ruoyi.order.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.Payment;
import com.ruoyi.order.service.IPaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 付款管理Controller
 * 
 * @author ruoyi
 * @date 2021-06-06
 */
@RestController
@RequestMapping("/order/payment")
public class PaymentController extends BaseController
{
    @Autowired
    private IPaymentService paymentService;

    /**
     * 查询付款管理列表
     */
    @PreAuthorize("@ss.hasPermi('order:payment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Payment payment)
    {
        startPage();
        List<Payment> list = paymentService.selectPaymentList(payment);
        return getDataTable(list);
    }

    /**
     * 导出付款管理列表
     */
    @PreAuthorize("@ss.hasPermi('order:payment:export')")
    @Log(title = "付款管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Payment payment)
    {
        List<Payment> list = paymentService.selectPaymentList(payment);
        ExcelUtil<Payment> util = new ExcelUtil<Payment>(Payment.class);
        return util.exportExcel(list, "payment");
    }

    /**
     * 获取付款管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:payment:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return AjaxResult.success(paymentService.selectPaymentById(paymentId));
    }

    /**
     * 新增付款管理
     */
    @PreAuthorize("@ss.hasPermi('order:payment:add')")
    @Log(title = "付款管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Payment payment)
    {
        return toAjax(paymentService.insertPayment(payment));
    }

    /**
     * 修改付款管理
     */
    @PreAuthorize("@ss.hasPermi('order:payment:edit')")
    @Log(title = "付款管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Payment payment)
    {
        return toAjax(paymentService.updatePayment(payment));
    }

    /**
     * 删除付款管理
     */
    @PreAuthorize("@ss.hasPermi('order:payment:remove')")
    @Log(title = "付款管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(paymentService.deletePaymentByIds(paymentIds));
    }
}
